package com.hc.concurrent_likes.service.impl;

import com.hc.concurrent_likes.entity.User;
import com.hc.concurrent_likes.entity.UserDTO;
import com.hc.concurrent_likes.mapper.UserMapper;
import com.hc.concurrent_likes.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    @Qualifier("userMapper")
    private UserMapper userMapper;

    @Override
    public UserDTO find(String id) {
        User user = userMapper.findById(id);
        return converModel2DTO(user);
    }

    /**
     * 将User实例转化成UserDTO
     * @param user
     * @return
     */
    private UserDTO converModel2DTO(User user){
        UserDTO userDTO = new UserDTO();
        userDTO.setId(user.getId());
        userDTO.setAccount(user.getAccount());
        userDTO.setName(user.getName());
        return userDTO;
    }
}
